package org.example.mapper.impl;


import org.apache.ibatis.session.SqlSession;
import org.example.entity.Student;
import org.example.mapper.StudentMapper;
import org.example.utils.SqlSessionUtil;

import java.util.List;

/**
 *  我们已经学习框架了
 *     有一些规范，需要大家在练习的过程中，就要遵守了
 *     对于接口实现类所在的包名，必须叫impl
 *     实现类的命名，必须是接口名+Impl
 */
public class StudentMapperImpl implements StudentMapper {
    @Override
    public Student getById(String id) {
        SqlSession session = SqlSessionUtil.getSession();
        Student s = session.selectOne("abc.getById", id);
        SqlSessionUtil.close(session);
        return s;
    }

    @Override
    public List<Student> getAll() {
        SqlSession session = SqlSessionUtil.getSession();
        List<Student> list = session.selectList("abc.getAll");
        SqlSessionUtil.close(session);
        return list;
    }

    @Override
    public void insert(Student s) {
        SqlSession session = SqlSessionUtil.getSession();
        session.insert("abc.insert",s);
        session.commit();
        SqlSessionUtil.close(session);
    }

    @Override
    public void update(Student s) {
        SqlSession session = SqlSessionUtil.getSession();
        session.update("abc.update",s);
        session.commit();
        SqlSessionUtil.close(session);
    }

    @Override
    public void delete(Student s) {
        SqlSession session = SqlSessionUtil.getSession();
        session.delete("abc.delete",s);
        session.commit();
        SqlSessionUtil.close(session);
    }
}
